* Core Analysis File

set more off

clear

cap n log close

log using 2b-Core-Analysis.log, replace

*********************************
*** CORE DATA REVIEW          ***
*********************************

* Show appendix table 1 values
use ethn classwkr perwt using ./temp/2000-WorkerResults.dta, clear
gen entr=perwt if classwkr==1
ren perwt total
collapse (sum) entr total, by(ethn) fast
sort ethn
save ./temp/t1-merger1, replace
use ethn self OVER1 Ibig Imax if self==0 using ./temp/2000-Core1, clear
drop self
for var OVER1 Ibig Imax: ren X TX
sort ethn
save ./temp/t1-merger2, replace
use if self==1 using ./temp/2000-Core1, clear
keep ethn OVER1-OVER4 size2000 iso2000 Ibig Imax
sort ethn
merge ethn using ./temp/t1-merger1
drop _m
sort ethn
merge ethn using ./temp/t1-merger2
drop _m
drop if ethn==1
for var size2000: replace X=exp(X)
gen selfsh=entr/total
gsort -OVER1
format OVER1-OVER4 TOVER1 %4.1f
format iso selfsh  %3.2f
format size2000 entr total %6.0f 
drop entr
order ethn OVER1-OVER4 TOVER1 iso selfsh total size2000
label define Idisp 10 "Agricultural production, crops", add
label define Idisp 11 "Veterinary and livestock services", add
label define Idisp 20 "Landscaping", add
label define Idisp 30 "Forestry, fishing and hunting", add
label define Idisp 40 "Mining", add
label define Idisp 60 "Construction", add
label define Idisp 100 "Food and kindred products", add
label define Idisp 132 "Textile mill products", add
label define Idisp 150 "Apparel and other finished textile products", add
label define Idisp 160 "Paper and allied products", add
label define Idisp 170 "Printing, publishing, and allied industries:", add
label define Idisp 180 "Chemicals and allied products", add
label define Idisp 200 "Petroleum and coal products", add
label define Idisp 210 "Rubber and misc. plastics products", add
label define Idisp 220 "Leather and leather products", add
label define Idisp 230 "Lumber and wood products, ex furniture", add
label define Idisp 242 "Furniture and fixtures", add
label define Idisp 250 "Stone, clay, glass and concrete products", add
label define Idisp 270 "Metal industries", add
label define Idisp 310 "Machinery and computing equipment", add
label define Idisp 340 "Electrical machinery and equipment", add
label define Idisp 350 "Transportation equipment", add
label define Idisp 370 "Professional/photographic equipment", add
label define Idisp 390 "Toys, amusement, and sporting goods", add
label define Idisp 391 "Miscellaneous manufacturing industries", add
label define Idisp 392 "Manufacturing industries, n.s.", add
label define Idisp 401 "Bus service and urban transit", add
label define Idisp 402 "Taxicab service", add
label define Idisp 410 "Trucking service", add
label define Idisp 411 "Warehousing and storage", add
label define Idisp 420 "Miscellaneous transportation", add
label define Idisp 440 "Communications", add
label define Idisp 471 "Utilities and sanitary services", add
label define Idisp 500 "Motor vehicles and equipment", add
label define Idisp 501 "Furniture and home furnishings", add
label define Idisp 502 "Lumber and construction materials", add
label define Idisp 510 "Machinery, equipment, and supplies", add
label define Idisp 511 "Metals and minerals, except petroleum", add
label define Idisp 512 "Electrical goods", add
label define Idisp 521 "Hardware, plumbing and heating supplies", add
label define Idisp 531 "Scrap and waste materials", add
label define Idisp 532 "Miscellaneous wholesale, durable goods", add
label define Idisp 540 "Paper and paper products", add
label define Idisp 541 "Drugs, chemicals, and allied products", add
label define Idisp 542 "Apparel, fabrics, and notions", add
label define Idisp 550 "Groceries and related products", add
label define Idisp 551 "Farm-product raw materials", add
label define Idisp 552 "Petroleum products", add
label define Idisp 560 "Alcoholic beverages", add
label define Idisp 561 "Farm supplies", add
label define Idisp 562 "Miscellaneous wholesale, nondurable goods", add
label define Idisp 571 "Wholesale trade, n.s.", add
label define Idisp 580 "Lumber and building material retailing", add
label define Idisp 581 "Hardware stores", add
label define Idisp 582 "Retail nurseries and garden stores", add
label define Idisp 591 "Misc. merchandise stores", add
label define Idisp 601 "Grocery stores", add
label define Idisp 610 "Retail bakeries", add
label define Idisp 611 "Food stores, n.e.c.", add
label define Idisp 612 "Motor vehicle dealers", add
label define Idisp 620 "Auto and home supply stores", add
label define Idisp 621 "Gasoline service stations", add
label define Idisp 622 "Miscellaneous vehicle dealers", add
label define Idisp 623 "Apparel and accessory stores, except shoe", add
label define Idisp 630 "Shoe stores", add
label define Idisp 631 "Furniture and home furnishings stores", add
label define Idisp 633 "Household appliance stores", add
label define Idisp 682 "Misc. retail stores", add
label define Idisp 641 "Eating and drinking places", add
label define Idisp 642 "Drug stores", add
label define Idisp 650 "Liquor stores", add
label define Idisp 651 "Sporting goods, bicycles, and hobby stores", add
label define Idisp 652 "Book and stationery stores", add
label define Idisp 660 "Jewelry stores", add
label define Idisp 662 "Sewing, needlework, and piece goods stores", add
label define Idisp 663 "Catalog and mail order houses", add
label define Idisp 670 "Vending machine operators", add
label define Idisp 671 "Direct selling establishments", add
label define Idisp 672 "Fuel dealers", add
label define Idisp 681 "Retail florists", add
label define Idisp 691 "Retail trade, n.s.", add
label define Idisp 700 "Banking", add
label define Idisp 702 "Savings and credit institutions", add
label define Idisp 710 "Security, commodity brokerage, and investment companies", add
label define Idisp 711 "Insurance", add
label define Idisp 712 "Real estate, including real estate-insurance offices", add
label define Idisp 721 "Advertising", add
label define Idisp 722 "Services to dwellings", add
label define Idisp 731 "Personnel supply services", add
label define Idisp 732 "Computer and data processing services", add
label define Idisp 740 "Detective and protective services", add
label define Idisp 741 "Business services, n.e.c.", add
label define Idisp 750 "Automotive renting and parking", add
label define Idisp 751 "Automotive repair and related services", add
label define Idisp 752 "Electrical repair shops", add
label define Idisp 760 "Miscellaneous repair services", add
label define Idisp 761 "Private households", add
label define Idisp 762 "Hotels and motels", add
label define Idisp 770 "Lodging places, except hotels and motels", add
label define Idisp 771 "Laundry, cleaning, and garment services", add
label define Idisp 772 "Beauty shops", add
label define Idisp 780 "Barber shops", add
label define Idisp 781 "Funeral service and crematories", add
label define Idisp 791 "Misc. personal services", add
label define Idisp 800 "Theaters and video rental", add
label define Idisp 810 "Misc entertainment and recreation services", add
label define Idisp 812 "Physicians & health practitioners", add
label define Idisp 820 "Offices and clinics of dentists", add
label define Idisp 821 "Offices and clinics of chiropractors", add
label define Idisp 822 "Offices and clinics of optometrists", add
label define Idisp 831 "Hospitals", add
label define Idisp 832 "Nursing and personal care facilities", add
label define Idisp 840 "Health services, n.e.c.", add
label define Idisp 841 "Legal services", add
label define Idisp 842 "Elementary and secondary schools", add
label define Idisp 850 "Educational institutions", add
label define Idisp 860 "Educational services", add
label define Idisp 862 "Child care services", add
label define Idisp 870 "Residential care facilities", add
label define Idisp 871 "Social services, n.e.c.", add
label define Idisp 872 "Museums, art galleries, and zoos", add
label define Idisp 882 "Engineering, architectural, and surveying services", add
label define Idisp 890 "Accounting, auditing, and bookkeeping services", add
label define Idisp 891 "R&D and testing services", add
label define Idisp 892 "Management and public relations services", add
label define Idisp 893 "Misc. professional services", add
for any Ibig Imax TIbig TImax: label values X Idisp
drop TImax
outsheet using ./output/TA1.csv, c replace
sleep 5000
for num 1/2: erase ./temp/t1-mergerX.dta

*********************************
*** IV & SIM CONTROLS         ***
*********************************

use ./data-input/residential-isolation-sim1, clear
gen Edev1=Edev if n==0
replace Edev=. if n==0
collapse (mean) Edev*, by(ethn) fast
gen Edev2=Edev1/Edev
drop Edev
sort ethn
save ./temp/residential-isolation, replace

* Ethnic controls
use if year==2000 & ethn!=1 using ./temp/1a-US-Master2.dta, clear
g valid=(sex==1 & approx_age>=16 & age>=22 & age<=70 & ethn!=1 & classwkr!=0)
keep if valid==1
gen Ztotal=perwt
gen Cage2235=perwt if age>=22 & age<=35
gen Cage3655=perwt if age>=36 & age<=55
gen Cage5670=perwt if age>=56 & age<=70
gen Cmarried=perwt if marst==1 | marst==2
gen CEngWell=perwt if speakeng>=2 & speakeng<=5
gen CHS=perwt if educ<=6
gen CSC=perwt if educ>=7 & educ<=9
gen CCol=perwt if educ>=10 & educ!=.
collapse (sum) C* Ztotal, by(ethn) fast
for var C*: replace X=X/Ztotal
drop CHS Cage2235 Ztotal
sort ethn
merge eth using ./temp/residential-isolation 
erase ./temp/residential-isolation.dta
drop _m
sort ethn
ren Edev2 Edev
save ./temp/iv-controls, replace

* Simulations based upon group count (no perwt)
use if ethn!=1 using ./temp/2000-WorkerResults.dta, clear
gen cttot=1 
gen ctself=1 if classwkr==1
collapse (sum) ctself, by(ethn) fast
ren ctself trial
sort trial
merge trial using ./data-input/trials2, nok
drop _m trial
renpfix O QO
sort ethn
save ./temp/temp-sim, replace

*********************************
*** INDUSTRY ORDER PREP       ***
*********************************
*Ibig = biggest sector of self-employment
*Imax = sector of self-employment's max overage

* Industry size
use ./temp/2000-WorkerResults.dta, clear
gen cttot=perwt  
gen ctself=perwt if classwkr==1
collapse (sum) ct*, by(ind1990) fast
sort ind1990
save ./temp/2000-isize, replace

* Ethnic average industry size
use if ethn!=1 using ./temp/2000-WorkerResults.dta, clear
sort ind1990
merge ind1990 using ./temp/2000-isize
for var cttot ctself: gen TX=X*perwt if classwkr!=1
for var cttot ctself: gen EX=X*perwt if classwkr==1
gen Tperwt=perwt if classwkr!=1
gen Eperwt=perwt if classwkr==1
collapse (sum) T* E*, by(ethn) fast
for any cttot ctself: gen avTX=TX/Tperwt \ gen avEX=EX/Eperwt
drop E* T*
sort ethn
save ./temp/2000-ethav, replace

* Ethnic wage employment max industry
use if ethn!=1 using ./temp/2000-WorkerResults.dta, clear
gen Tperwt=perwt if classwkr!=1
collapse (sum) T*, by(ethn ind1990) fast
gsort ethn -Tperwt
drop if ethn==ethn[_n-1]
sort ethn
ren ind1990 Tbig
save ./temp/2000-ethmax, replace

* Combine files
use ethn self Ibig if self==1 using ./temp/2000-Core1, clear 
ren Ibig ind1990
sort ind1990
merge ind1990 using ./temp/2000-isize, nok
drop _m
renpfix ct Ibig
ren ind1990 Ibig
sort ethn
merge ethn using ./temp/2000-ethav, nok
drop _m
sort ethn
merge ethn using ./temp/2000-ethmax, nok
drop _m
ren Tbig ind1990
sort ind1990
merge ind1990 using ./temp/2000-isize, nok
drop _m
renpfix ct Tbig
ren ind1990 Tbig
for var avT* avE* Ibigtot Ibigself Tbigtot Tbigself: replace X=ln(X)
sort ethn
save ./temp/2000-ind-size, replace

* Visual display
use ./temp/2000-isize
egen Iranktot=rank(cttot)
egen Irankself=rank(ctself)
sort ind1990
save ./temp/2000-Irank, replace
use ethn size2000 isox2000 self if self==1 using ./temp/2000-Core1, clear
drop self
sort ethn
save ./temp/2000-iso-input, replace
use if ethn!=1 using ./temp/2000-WorkerResults.dta, clear
gen Tperwt=perwt if classwkr!=1
gen Eperwt=perwt if classwkr==1
collapse (sum) T* E*, by(ethn ind1990) fast
fillin ethn ind1990
for var T* E*: replace X=0 if X==. 
gen temp1=Tperwt+Eperwt
egen Gsize=total(temp1), by(ethn)
drop temp1
sort ind1990
merge ind1990 using ./temp/2000-Irank
drop _m
sort ethn
merge ethn using ./temp/2000-iso-input
drop _m
egen temp1=pctile(isox), p(50)
egen temp2=pctile(size), p(50)
gen group=.
assert size!=. & isox!=.
replace group=1 if isox>=temp1 & size<temp2
replace group=2 if isox<temp1 & size<temp2
replace group=3 if isox>=temp1 & size>=temp2
replace group=4 if isox<temp1 & size>=temp2
preserve
collapse (sum) Eperwt, by(group Iranktot) fast
egen temp1=total(Eperwt), by(group)
replace Eperwt=Eperwt/temp1
drop temp1
sort group Irank
by group: gen n=[_n]
gen Idistr=Eperwt if n==1
replace Idistr=Idistr[_n-1]+Eperwt if n>1 & group==group[_n-1]
keep Idistr Irank group
reshape wide Idistr, i(Irank) j(group)
list, clean noobs
restore
collapse (sum) Eperwt, by(group Irankself) fast
egen temp1=total(Eperwt), by(group)
replace Eperwt=Eperwt/temp1
drop temp1
sort group Irank
by group: gen n=[_n]
gen Idistr=Eperwt if n==1
replace Idistr=Idistr[_n-1]+Eperwt if n>1 & group==group[_n-1]
keep Idistr Irank group
reshape wide Idistr, i(Irank) j(group)
list, clean noobs

use ethn perwt ind1990 classwkr if ethn==1 using ./temp/2000-WorkerResults.dta, clear
gen Tperwt=perwt if classwkr!=1
gen Eperwt=perwt if classwkr==1
collapse (sum) T* E*, by(ind1990) fast
sort ind1990
merge ind1990 using ./temp/2000-Irank
drop _m
gen group=5
preserve
collapse (sum) Eperwt, by(group Iranktot) fast
egen temp1=total(Eperwt), by(group)
replace Eperwt=Eperwt/temp1
drop temp1
sort group Irank
by group: gen n=[_n]
gen Idistr=Eperwt if n==1
replace Idistr=Idistr[_n-1]+Eperwt if n>1 & group==group[_n-1]
keep Idistr Irank group
reshape wide Idistr, i(Irank) j(group)
list Idistr, clean noobs
restore
collapse (sum) Eperwt, by(group Irankself) fast
egen temp1=total(Eperwt), by(group)
replace Eperwt=Eperwt/temp1
drop temp1
sort group Irank
by group: gen n=[_n]
gen Idistr=Eperwt if n==1
replace Idistr=Idistr[_n-1]+Eperwt if n>1 & group==group[_n-1]
keep Idistr Irank group
reshape wide Idistr, i(Irank) j(group)
list Idistr, clean noobs

*********************************
*** 2000 CORE ANALYSIS        ***
*********************************

use ./temp/2000-Core1, clear

*** Prepare baseline files
* T means everyone is included
* F means five year window restriction
* I means exclude natives
* R means restriction to min count in cells
* N means no taxi industry
for num 1/4: gen ZOVERX=OVERX if self==1
for num 1/4: gen temp1=OVERX if self==0 \ egen ZOVERXT=mean(temp1), by(ethn) \ drop temp1
for num 1: gen temp1=OVERX if self==2 \ egen ZOVERXF=mean(temp1), by(ethn) \ drop temp1
for num 1: gen temp1=OVERX if self==3 \ egen ZOVERXI=mean(temp1), by(ethn) \ drop temp1
for num 1/4: gen temp1=OVERX if self==4 \ egen ZOVERXR=mean(temp1), by(ethn) \ drop temp1
for num 1: gen temp1=OVERX if self==5 \ egen ZOVERXN=mean(temp1), by(ethn) \ drop temp1
keep if self==1
drop OVER* self Ibig Imax

* Merge external inputs
sort ethn
merge ethn using ./temp/iv-controls, nok
drop _m 
sort ethn
merge ethn using ./temp/temp-sim, nok 
drop _m 
gen CI50=(ZOVER1>QOVER1)
gen CI90=(ZOVER1>QOVER1+1.64*QOVER1sd)
gen CI95=(ZOVER1>QOVER1+1.96*QOVER1sd)
su ZOVER1 QOVER1 QOVER1sd CI*
drop QOVER1sd CI50
ren QOVER1 ZOVER1Sim
sort ethn
merge ethn using ./temp/2000-ind-size, nok
drop _m CI*

*** Define size and iso for year and restrict on sample
for Z in any iso isox size: g Z=Z2000
drop iso1980-iso2018 isox1980-isox2018 size1980-size2018 gplu lplu rplu gwtd lwtd rwtd
gen dropx=(size==. | isox==. | ZOVER1==.)
list ethn ZOVER1 size isox if dropx==1
drop dropx

*** Variable prep
egen isoc=rmean(iso1991 iso2011)
replace isoc=. if iso1991==. | iso2011==.
for var dist population: replace X=ln(X)
ren weight wt
gen border=(ethn==15000 | ethn==20000)
gen distsq=dist^2
reg size dist population [aw=wt], r
predict sizehat
qui reg size dist border population [aw=wt], r
predict sizehat_border
qui reg size dist distsq population [aw=wt], r
predict sizehat_distsq
for var size sizehat*: replace X=-X
sum

for any ZOVER1 size sizehat isox iso1991 iso2011 isoc: gen RX=X
foreach y of var ZOVER* size sizehat sizehat_border sizehat_distsq iso isox iso1991 iso2011 isoc gplucomp lplucomp rplucomp dist distsq population Edev {
	qui su `y', d
	replace `y'=r(p99) if `y'>r(p99) & `y'!=.
	replace `y'=r(p1) if `y'<r(p1)
	qui su `y', d
	replace `y'=(`y'-r(mean))/r(sd)
	}
for var R*: qui su X, d \ replace X=(X-r(mean))/r(sd)

*** Continent FE
gen bpl=ethn
gen cont=""
replace bpl=52100 if (bpl==2 | bpl==3)
replace bpl=54200 if bpl==4
replace bpl=52200 if bpl==5
replace bpl=50040 if bpl==6
replace cont="North America" if bpl<=19900
replace cont="Central America/Caribbean" if (bpl>=20000 & bpl<=29900)
replace cont="South America" if (bpl>=30000 & bpl<=30091)
replace cont="Europe" if (bpl>=40000 & bpl<=49900)
replace cont="Asia" if (bpl>=50000 & bpl<=59900)
replace cont="Africa" if (bpl>=60000 & bpl<=60099)
replace cont="Oceania" if (bpl>=70000 & bpl<=71090)
replace cont="Antartica" if (bpl>=80000 & bpl<=80050)
replace cont="Abroad/Unknown" if bpl>=90000
tab ethn if cont==""

*** Table A1 - Descriptive Stats
* See above

*** Table A2 - Correlation Matrix
pwcorr ZOVER1 ZOVER2 ZOVER3 ZOVER4 ZOVER1T ZOVER2T ZOVER3T ZOVER4T
for var ZOVER1 ZOVER2 ZOVER3 ZOVER4 ZOVER1T ZOVER2T ZOVER3T ZOVER4T: egen rankX=rank(X)
pwcorr rank*
drop ZOVER2T ZOVER3T ZOVER4T rank*

*** Table 1 - OLS Baseline
eststo clear
estimates clear
eststo: regress ZOVER1 size isox [aw=wt], r
eststo: regress ZOVER1T size isox [aw=wt], r
eststo: regress ZOVER1I size isox [aw=wt], r
eststo: regress ZOVER1R size isox [aw=wt], r
eststo: regress ZOVER1F size isox [aw=wt], r
eststo: regress ZOVER1N size isox [aw=wt], r
eststo: regress ZOVER1 size isox C* [aw=wt], r
eststo: regress ZOVER1T size isox C* [aw=wt], r
eststo: regress ZOVER1I size isox C* [aw=wt], r
eststo: regress ZOVER1R size isox C* [aw=wt], r
eststo: regress ZOVER1F size isox C* [aw=wt], r
eststo: regress ZOVER1N size isox C* [aw=wt], r
esttab _all using ".\output\T1.csv", replace se r2 ar2 b(%9.3f) se(%9.3f) star( + .1 ++ .05 +++ .01) order(size isox) keep(size isox)

*** Table 2 - OLS Robustness
eststo clear 
estimates clear
eststo: regress ZOVER1 size isox [aw=wt], r
eststo: regress ZOVER1 size isox, r
eststo: regress RZOVER1 Rsize Risox [aw=wt], r
eststo: areg ZOVER1 size isox [aw=wt], a(cont) r
eststo: qreg ZOVER1 size isox, vce(r)
eststo: bootstrap, reps(100) seed(123456789): reg ZOVER1 size isox, r
eststo: regress ZOVER1 size isox ZOVER1Sim [aw=wt], r
eststo: regress ZOVER1 size isox C* [aw=wt], r
eststo: regress ZOVER1 size isox C*, r
eststo: regress RZOVER1 Rsize Risox C* [aw=wt], r
eststo: areg ZOVER1 size isox C* [aw=wt], a(cont) r
eststo: qreg ZOVER1 size isox C*, vce(r)
eststo: bootstrap, reps(100) seed(123456789): reg ZOVER1 size isox C*, r
eststo: regress ZOVER1 size isox ZOVER1Sim C* [aw=wt], r
esttab _all using ".\output\T2.csv", replace se r2 ar2 b(%9.3f) se(%9.3f) star( + .1 ++ .05 +++ .01) order(size isox Rsize Risox) keep(size isox Rsize Risox)

*** Table 3 - OLS Overage Metric Designs
eststo clear
estimates clear
eststo: regress ZOVER1 size isox [aw=wt], r
eststo: regress ZOVER2 size isox [aw=wt], r
eststo: regress ZOVER3 size isox [aw=wt], r
eststo: regress ZOVER4 size isox [aw=wt], r
eststo: regress ZOVER1 size isox C* [aw=wt], r
eststo: regress ZOVER2 size isox C* [aw=wt], r
eststo: regress ZOVER3 size isox C* [aw=wt], r
eststo: regress ZOVER4 size isox C* [aw=wt], r
esttab _all using ".\output\T3.csv", replace se r2 ar2 b(%9.3f) se(%9.3f) star( + .1 ++ .05 +++ .01) order(size isox) keep(size isox)

*** Table 4 - OLS Fixed Effects and Extensions
* Done in extension file

*** Table 5 - OLS Isolation Variables
eststo clear 
estimates clear
eststo: regress ZOVER1 size isox [aw=wt], r
eststo: regress ZOVER1 size Edev [aw=wt], r
eststo: regress ZOVER1 size gplucomp [aw=wt], cl(wacziarggroups)
eststo: regress ZOVER1 size lplucomp [aw=wt], cl(wacziarggroups)
eststo: regress ZOVER1 size rplucomp [aw=wt], cl(wacziarggroups)
eststo: regress ZOVER1 size isox Edev gplucomp lplucomp rplucomp [aw=wt], cl(wacziarggroups)
eststo: regress ZOVER1 size isox C* [aw=wt], r
eststo: regress ZOVER1 size Edev C* [aw=wt], r
eststo: regress ZOVER1 size gplucomp C* [aw=wt], cl(wacziarggroups)
eststo: regress ZOVER1 size lplucomp C* [aw=wt], cl(wacziarggroups)
eststo: regress ZOVER1 size rplucomp C* [aw=wt], cl(wacziarggroups)
eststo: regress ZOVER1 size isox Edev gplucomp lplucomp rplucomp C* [aw=wt], cl(wacziarggroups)
esttab _all using ".\output\T5.csv", replace se r2 ar2 b(%9.3f) se(%9.3f) star( + .1 ++ .05 +++ .01) keep(size isox Edev gplucomp lplucomp rplucomp)

*** Table 6 - IV Baseline
eststo clear 
estimates clear
eststo: qui regress size sizehat iso1991 [aw=wt], cl(ukgroups)
eststo: qui regress isox sizehat iso1991 [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat iso1991) [aw=wt], first cl(ukgroups)
	estat firststage, forcenonrobust all
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
eststo: qui regress size sizehat iso1991 C* [aw=wt], cl(ukgroups)
eststo: qui regress isox sizehat iso1991 C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat iso1991) C* [aw=wt], first cl(ukgroups)
	estat firststage, forcenonrobust all
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
esttab _all using ".\output\T6a.csv", replace se r2 ar2 b(%9.3f) se(%9.3f) stats(N p_value) star( + .1 ++ .05 +++ .01) order(size isox sizehat iso1991) keep(size isox sizehat iso1991) 
eststo clear 
estimates clear
eststo: qui regress size sizehat isoc [aw=wt], cl(ukgroups)
eststo: qui regress isox sizehat isoc [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat isoc) [aw=wt], first cl(ukgroups)
	estat firststage, forcenonrobust all
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
eststo: qui regress size sizehat isoc C* [aw=wt], cl(ukgroups)
eststo: qui regress isox sizehat isoc C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat isoc) C* [aw=wt], first cl(ukgroups)
	estat firststage, forcenonrobust all
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
esttab _all using ".\output\T6b.csv", replace se r2 ar2 b(%9.3f) se(%9.3f) stats(N p_value) star( + .1 ++ .05 +++ .01) order(size isox sizehat isoc) keep(size isox sizehat isoc) 

*** Table 8 - Industry Size
eststo clear 
estimates clear
eststo: qui regress avEctself size isox [aw=wt], r
eststo: qui regress avEcttot size isox [aw=wt], r
eststo: qui regress Ibigself size isox [aw=wt], r
eststo: qui regress Ibigtot size isox [aw=wt], r
eststo: qui regress avTctself size isox [aw=wt], r
eststo: qui regress avTcttot size isox [aw=wt], r
eststo: qui regress Tbigself size isox [aw=wt], r
eststo: qui regress Tbigtot size isox [aw=wt], r
eststo: qui regress avEctself size isox C* [aw=wt], r
eststo: qui regress avEcttot size isox C* [aw=wt], r
eststo: qui regress Ibigself size isox  C* [aw=wt], r
eststo: qui regress Ibigtot size isox C* [aw=wt], r
eststo: qui regress avTctself size isox C* [aw=wt], r
eststo: qui regress avTcttot size isox C* [aw=wt], r
eststo: qui regress Tbigself size isox C* [aw=wt], r
eststo: qui regress Tbigtot size isox C* [aw=wt], r
esttab _all using ".\output\T8.csv", replace se r2 ar2 b(%9.3f) se(%9.3f) star( + .1 ++ .05 +++ .01) order(size isox) keep(size isox)

*** Table A3 - OLS Non-parametric
eststo clear 
estimates clear
replace size=-size
_pctile size, nq(1000)
g size33 = 0
replace size33 = 1 if size <= r(r333)
g size66 = 0
replace size66 = 1 if size > r(r333) & size <= r(r666)
g size99 = 0
replace size99 = 1 if size > r(r666) & size!=.
replace size=-size
_pctile isox, nq(1000)
g iso33 = 0
replace iso33 = 1 if isox <= r(r333)
g iso66 = 0
replace iso66 = 1 if isox > r(r333) & isox <= r(r666)
g iso99 = 0
replace iso99 = 1 if isox > r(r666) & isox!=.
g size33_iso99 = size33 * iso99
g size33_iso66 = size33 * iso66
g size33_iso33 = size33 * iso33
g size66_iso99 = size66 * iso99
g size66_iso66 = size66 * iso66
g size66_iso33 = size66 * iso33
g size99_iso66 = size99 * iso66
g size99_iso99 = size99 * iso99
eststo: reg ZOVER1 size33_iso99 size33_iso66 size33_iso33 size66_iso99 size66_iso66 size66_iso33 size99_iso99 size99_iso66 [aw=wt], r
eststo: reg ZOVER2 size33_iso99 size33_iso66 size33_iso33 size66_iso99 size66_iso66 size66_iso33 size99_iso99 size99_iso66 [aw=wt], r
eststo: reg ZOVER3 size33_iso99 size33_iso66 size33_iso33 size66_iso99 size66_iso66 size66_iso33 size99_iso99 size99_iso66 [aw=wt], r
eststo: reg ZOVER4 size33_iso99 size33_iso66 size33_iso33 size66_iso99 size66_iso66 size66_iso33 size99_iso99 size99_iso66 [aw=wt], r
eststo: reg ZOVER1 size33_iso99 size33_iso66 size33_iso33 size66_iso99 size66_iso66 size66_iso33 size99_iso99 size99_iso66 C* [aw=wt], r
eststo: reg ZOVER2 size33_iso99 size33_iso66 size33_iso33 size66_iso99 size66_iso66 size66_iso33 size99_iso99 size99_iso66 C* [aw=wt], r
eststo: reg ZOVER3 size33_iso99 size33_iso66 size33_iso33 size66_iso99 size66_iso66 size66_iso33 size99_iso99 size99_iso66 C* [aw=wt], r
eststo: reg ZOVER4 size33_iso99 size33_iso66 size33_iso33 size66_iso99 size66_iso66 size66_iso33 size99_iso99 size99_iso66 C* [aw=wt], r
esttab _all using ".\output\TA3.csv", replace se r2 ar2 b(%9.3f) se(%9.3f) star( + .1 ++ .05 +++ .01) order(size33_iso99 size33_iso66 size33_iso33 size66_iso99 size66_iso66 size66_iso33 size99_iso99 size99_iso66) keep(size33_iso99 size33_iso66 size33_iso33 size66_iso99 size66_iso66 size66_iso33 size99_iso99 size99_iso66) 
drop size33* size66* size99* iso33 iso66 iso99

*** Table A4 - IV Spanish In-Marriage Rate
eststo clear 
estimates clear
eststo: qui regress size sizehat iso2011 [aw=wt], cl(spaingroups)
eststo: qui regress isox sizehat iso2011 [aw=wt], cl(spaingroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat iso2011) [aw=wt], first cl(spaingroups)
	estat firststage, forcenonrobust all
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
eststo: qui regress size sizehat iso2011 C* [aw=wt], cl(spaingroups)
eststo: qui regress isox sizehat iso2011 C* [aw=wt], cl(spaingroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat iso2011) C* [aw=wt], first cl(spaingroups)
	estat firststage, forcenonrobust all
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
eststo: qui regress size sizehat iso1991 iso2011 [aw=wt], cl(spaingroups)
eststo: qui regress isox sizehat iso1991 iso2011 [aw=wt], cl(spaingroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat iso1991 iso2011) [aw=wt], first cl(spaingroups)
	estat firststage, forcenonrobust all
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
	estat overid, forceweights forcenonrobust
eststo: qui regress size sizehat iso1991 iso2011 C* [aw=wt], cl(spaingroups)
eststo: qui regress isox sizehat iso1991 iso2011 C* [aw=wt], cl(spaingroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat iso1991 iso2011) C* [aw=wt], first cl(spaingroups)
	estat firststage, forcenonrobust all
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
	estat overid, forceweights forcenonrobust
esttab _all using ".\output\TA4.csv", replace se r2 ar2 b(%9.3f) se(%9.3f) stats(N p_value) star( + .1 ++ .05 +++ .01) order(size isox sizehat iso2011 iso1991) keep(size isox sizehat iso2011 iso1991)

*** Table A5 - IV Robustness
* BS slightly adjusted
eststo clear 
estimates clear
eststo: ivregress 2sls ZOVER1 (size isox=sizehat iso1991) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat iso1991), cl(ukgroups)
eststo: ivregress 2sls RZOVER1 (Rsize Risox=Rsizehat Riso1991) [aw=wt], cl(ukgroups)
eststo: bootstrap, reps(100) seed(123456789): ivregress 2sls ZOVER1 (size isox=sizehat iso1991), cl(ukgroups)
eststo: ivregress 2sls ZOVER1 size (isox=iso1991) ZOVER1Sim [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat iso1991) ZOVER1Sim [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat iso1991) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat iso1991) C*, cl(ukgroups)
eststo: ivregress 2sls RZOVER1 (Rsize Risox=Rsizehat Riso1991) C* [aw=wt], cl(ukgroups)
eststo: bootstrap, reps(100) seed(1234567891): ivregress 2sls ZOVER1 C* (size isox=sizehat iso1991), cl(ukgroups)
eststo: ivregress 2sls ZOVER1 size (isox=iso1991) ZOVER1Sim C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat iso1991) ZOVER1Sim C* [aw=wt], cl(ukgroups)
esttab _all using ".\output\TA5a.csv", replace se r2 ar2 b(%9.3f) se(%9.3f) star( + .1 ++ .05 +++ .01) order(size isox Rsize Risox) keep(size isox Rsize Risox) 
eststo clear 
estimates clear
eststo: ivregress 2sls ZOVER1 (size isox=sizehat isoc) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat isoc), cl(ukgroups)
eststo: ivregress 2sls RZOVER1 (Rsize Risox=Rsizehat Risoc) [aw=wt], cl(ukgroups)
eststo: bootstrap, reps(100) seed(123456789): ivregress 2sls ZOVER1 (size isox=sizehat isoc), cl(ukgroups)
eststo: ivregress 2sls ZOVER1 size (isox=isoc) ZOVER1Sim [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat isoc) ZOVER1Sim [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat isoc) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat isoc) C*, cl(ukgroups)
eststo: ivregress 2sls RZOVER1 (Rsize Risox=Rsizehat Risoc) C* [aw=wt], cl(ukgroups)
eststo: bootstrap, reps(100) seed(1234567891): ivregress 2sls ZOVER1 C* (size isox=sizehat isoc), cl(ukgroups)
eststo: ivregress 2sls ZOVER1 size (isox=isoc) ZOVER1Sim C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat isoc) ZOVER1Sim C* [aw=wt], cl(ukgroups)
esttab _all using ".\output\TA5b.csv", replace se r2 ar2 b(%9.3f) se(%9.3f) star( + .1 ++ .05 +++ .01) order(size isox Rsize Risox) keep(size isox Rsize Risox)

*** Table A6 - IV Overage Metric Designs
eststo clear
estimates clear
eststo: ivregress 2sls ZOVER1 (size isox=sizehat iso1991) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1T (size isox=sizehat iso1991) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1I (size isox=sizehat iso1991) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1R (size isox=sizehat iso1991) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1F (size isox=sizehat iso1991) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1N (size isox=sizehat iso1991) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat iso1991) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1T (size isox=sizehat iso1991) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1I (size isox=sizehat iso1991) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1R (size isox=sizehat iso1991) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1F (size isox=sizehat iso1991) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1N (size isox=sizehat iso1991) C* [aw=wt], cl(ukgroups)
esttab _all using ".\output\TA6a.csv", replace se r2 ar2 b(%9.3f) se(%9.3f) stats(N p_value) star( + .1 ++ .05 +++ .01) order(size isox) keep(size isox) 
eststo clear
estimates clear
eststo: ivregress 2sls ZOVER1 (size isox=sizehat isoc) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1T (size isox=sizehat isoc) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1I (size isox=sizehat isoc) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1R (size isox=sizehat isoc) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1F (size isox=sizehat isoc) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1N (size isox=sizehat isoc) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat isoc) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1T (size isox=sizehat isoc) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1I (size isox=sizehat isoc) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1R (size isox=sizehat isoc) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1F (size isox=sizehat isoc) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1N (size isox=sizehat isoc) C* [aw=wt], cl(ukgroups)
esttab _all using ".\output\TA6b.csv", replace se r2 ar2 b(%9.3f) se(%9.3f) stats(N p_value) star( + .1 ++ .05 +++ .01) order(size isox) keep(size isox) 

*** Table A7 - IV Overage Metric Designs
eststo clear
estimates clear
eststo: ivregress 2sls ZOVER1 (size isox=sizehat iso1991) [aw=wt], cl(ukgroups)
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
eststo: ivregress 2sls ZOVER2 (size isox=sizehat iso1991) [aw=wt], cl(ukgroups)
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
eststo: ivregress 2sls ZOVER3 (size isox=sizehat iso1991) [aw=wt], cl(ukgroups)
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
eststo: ivregress 2sls ZOVER4 (size isox=sizehat iso1991) [aw=wt], cl(ukgroups)
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat iso1991) C* [aw=wt], cl(ukgroups)
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
eststo: ivregress 2sls ZOVER2 (size isox=sizehat iso1991) C* [aw=wt], cl(ukgroups)
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
eststo: ivregress 2sls ZOVER3 (size isox=sizehat iso1991) C* [aw=wt], cl(ukgroups)
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
eststo: ivregress 2sls ZOVER4 (size isox=sizehat iso1991) C* [aw=wt], cl(ukgroups)
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
esttab _all using ".\output\TA7a.csv", replace se r2 ar2 b(%9.3f) se(%9.3f) stats(N p_value) star( + .1 ++ .05 +++ .01) order(size isox) keep(size isox) 
eststo clear
estimates clear
eststo: ivregress 2sls ZOVER1 (size isox=sizehat isoc) [aw=wt], cl(ukgroups)
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
eststo: ivregress 2sls ZOVER2 (size isox=sizehat isoc) [aw=wt], cl(ukgroups)
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
eststo: ivregress 2sls ZOVER3 (size isox=sizehat isoc) [aw=wt], cl(ukgroups)
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
eststo: ivregress 2sls ZOVER4 (size isox=sizehat isoc) [aw=wt], cl(ukgroups)
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat isoc) C* [aw=wt], cl(ukgroups)
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
eststo: ivregress 2sls ZOVER2 (size isox=sizehat isoc) C* [aw=wt], cl(ukgroups)
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
eststo: ivregress 2sls ZOVER3 (size isox=sizehat isoc) C* [aw=wt], cl(ukgroups)
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
eststo: ivregress 2sls ZOVER4 (size isox=sizehat isoc) C* [aw=wt], cl(ukgroups)
	estat endogenous, forceweights
	estadd scalar p_value = r(p_regF)
esttab _all using ".\output\TA7b.csv", replace se r2 ar2 b(%9.3f) se(%9.3f) stats(N p_value) star( + .1 ++ .05 +++ .01) order(size isox) keep(size isox) 

*** Table A8 - IV Gravity Formats 
eststo clear 
estimates clear
eststo: ivregress 2sls ZOVER1 (size isox=sizehat iso1991) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat_border iso1991) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat_distsq iso1991) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=dist population iso1991) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=dist population border iso1991) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=dist population distsq iso1991) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat iso1991) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat_border iso1991) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat_distsq iso1991) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=dist population iso1991) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=dist population border iso1991) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=dist population distsq iso1991) C* [aw=wt], cl(ukgroups)
esttab _all using ".\output\TA8a.csv", replace se r2 ar2 b(%9.3f) se(%9.3f) star( + .1 ++ .05 +++ .01) order(size isox) keep(size isox)
eststo clear 
estimates clear
eststo: ivregress 2sls ZOVER1 (size isox=sizehat isoc) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat_border isoc) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat_distsq isoc) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=dist population isoc) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=dist population border isoc) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=dist population distsq isoc) [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat isoc) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat_border isoc) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=sizehat_distsq isoc) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=dist population isoc) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=dist population border isoc) C* [aw=wt], cl(ukgroups)
eststo: ivregress 2sls ZOVER1 (size isox=dist population distsq isoc) C* [aw=wt], cl(ukgroups)
esttab _all using ".\output\TA8b.csv", replace se r2 ar2 b(%9.3f) se(%9.3f) star( + .1 ++ .05 +++ .01) order(size isox) keep(size isox)

for any isize ethav ethmax ind-size Irank iso-input: erase ./temp/2000-X.dta
erase ./temp/temp-sim.dta

* End of program
log close
